{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "4580c4ea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[80 88]\n",
      " [82 81]\n",
      " [75 81]]\n",
      "88\n",
      "[82 88]\n",
      "75\n",
      "[80 81 75]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "score = np.array([[80,88],[82,81],[75,81]])\n",
    "print(score)\n",
    "# 1. 获取所有数据最大值\n",
    "result = np.max(score)\n",
    "print(result)\n",
    "# 2. 获取数据最大值所在的轴\n",
    "result = np.max(score,axis=0)\n",
    "print(result)\n",
    "# 3. 获取最小值\n",
    "result = np.min(score)\n",
    "print(result)\n",
    "# 4. 获取某数据最小值所在的轴\n",
    "result = np.min(score,axis=1)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "id": "8acfdaca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 0 0 1 2]\n"
     ]
    }
   ],
   "source": [
    "# 5. 数据的比较\n",
    "result = np.maximum( [-2, -1, 0, 1, 2], 0 ) # 第一个参数中的每一个数与第二个参数比较返回大的\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "2738f994",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-2 -1  0  0  0]\n"
     ]
    }
   ],
   "source": [
    "result = np.minimum( [-2, -1, 0, 1, 2], 0 ) # 第一个参数中的每一个数与第二个参数比较返回小的\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "511e545d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4 5]\n"
     ]
    }
   ],
   "source": [
    "result = np.maximum( [-2, -1, 0, 1, 2], [1, 2, 3, 4, 5] )\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "4a4b688d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "81.167\n"
     ]
    }
   ],
   "source": [
    "# 6. 求平均值\n",
    "result = np.mean(score) # 获取所有数据的平均值\n",
    "print(round(result,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "id": "90ba049d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[79.         83.33333333]\n"
     ]
    }
   ],
   "source": [
    "result = np.mean(score,axis=0) # 获取某一行或者某一列的平均值\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "1ee92a8f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "******************************\n",
      "[[1 2 3]\n",
      " [5 7 9]]\n"
     ]
    }
   ],
   "source": [
    "# 7. 求前缀和\n",
    "arr = np.array([[1,2,3], [4,5,6]])\n",
    "print(arr)\n",
    "print('*'*30)\n",
    "print(arr.cumsum(0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "id": "bef866fe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1  3  6]\n",
      " [ 4  9 15]]\n"
     ]
    }
   ],
   "source": [
    "print(arr.cumsum(1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "5f9a38c6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2 1] [75 81]\n"
     ]
    }
   ],
   "source": [
    "# 8. argmin 求最小值索引\n",
    "result = np.argmin(score,axis=0)\n",
    "res=np.min(score,axis=0) #这样我们就可以知道最小的 81 是第二排的，是从前往后遍历的\n",
    "print(result,res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "id": "1b379f1d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2.94392029 3.29983165]\n"
     ]
    }
   ],
   "source": [
    "#标准差\n",
    "result = np.std(score,axis=0)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "id": "415074c3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13\n"
     ]
    }
   ],
   "source": [
    "# 10. 极 值\n",
    "result = np.ptp(score,axis=None)#就是最大值和最小值的差\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "id": "42568058",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 8.66666667 10.88888889]\n"
     ]
    }
   ],
   "source": [
    "#方差\n",
    "result = np.var(score,axis=0)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "720c10ad",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
